﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using SmartProject.BusinessObjects;

namespace SmartProject.BusinessRules
{
    /// <summary>
    /// Business rule to remove attachments related to a work item.
    /// </summary>
    public class RemoveMessageAttachments : BusinessRule
    {
        public override string Name
        {
            get { return "Remove all attachments related to a work item."; }
        }

        public override string Description
        {
            get { return "In addition to removing a work item, all associated attachments will also need to be removed."; }
        }

        /// <summary>
        /// Runs the implementation for removing associated attachments 
        /// when a work item is removed.
        /// </summary>
        /// <param name="data">Entity instance holding the Work Id.</param>
        public override void Implement(Entity data)
        {
            if (data.StoredProc == "smartProject_RemoveWork")
            {
                int workId = (int)data.GetAttributeValue("WorkId");
                WorkAttachment workAttachment = new WorkAttachment();
                workAttachment.SetAttribute("ReferenceId", workId);
                workAttachment.Remove();
            }
        }

        public override bool QueryBooleanProperty(string propertyName)
        {
            // Always return true. No properties to control.
            return true;
        }
    }
}
